Skip to content

Birmingham | ITP-Jan | Ahmad Roman Sanaye | Sprint 3 | Practice-tdd#1167

Open
RomanSanaye wants to merge 4 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-3-practice-tdd
Open

Birmingham | ITP-Jan | Ahmad Roman Sanaye | Sprint 3 | Practice-tdd#1167
RomanSanaye wants to merge 4 commits intoCodeYourFuture:mainfrom
RomanSanaye:coursework/sprint-3-practice-tdd

Conversation

@RomanSanaye
Copy link

@RomanSanaye RomanSanaye commented Mar 4, 2026

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implemented the following functions:

  • count
  • getOrdinalNumber
  • repeatStr

Each function handles the required cases and passes all Jest test cases, including edge cases (positive, zero, and negative values where applicable).

All tests are passing successfully.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 4, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed some minor format inconsistency.

Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode, as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?

If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.

If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:

  1. Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
  2. Edit settings.json and set Prettier as the default formatter for JS.
    See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Comment on lines +11 to +13
if (numberOfChar === 0) {
return `0 ${findCharacter} found.`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is expected to return an integer number. Returning a string would make the function difficult to use because the caller would need to check the data type of the return value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @cjyuan ,
I have updated the function so it now always returns an integer. Returning 0 instead of a string ensures the function is easier to use and matches the expected return type.

expect(getOrdinalNumber(33)).toEqual("33rd");
expect(getOrdinalNumber(333)).toEqual("333rd");
});
test("should append 'th' for numbers ending with 4 and more than 4", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... ending with 4-9, 0 might be more concise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the ordinal number test descriptions to group numbers ending in 4-9 and 0, making the tests more concise while still covering all cases.

// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

test("should print the original string", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"print" may suggest the function should output the string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the test description to say “return” instead of “print” to accurately reflect that the function returns a string rather than printing it.

// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

test("should return an empty string", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably make this description more informative by including the when ... part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have revised the test descriptions to include the input condition (when …) so they clearly state under what circumstances the function should return the expected result.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 13, 2026
@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
@cjyuan
Copy link
Contributor

cjyuan commented Mar 19, 2026

There is no new commits on this branch, and the comments are not yet addressed.

If you have responded to the comments, you may want to check if the responses are in "Pending" state. Other users cannot see the pending comments.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
Comment on lines 2 to 16
function countChar(stringOfCharacters, findCharacter) {
return 5
if (!stringOfCharacters || !findCharacter) {
return 0;
}
let numberOfChar = 0;
for (let wantedChar of stringOfCharacters) {
if (wantedChar === findCharacter) {
numberOfChar++;
}
if (numberOfChar === 0) {
return 0;
}
}
return numberOfChar;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has a bug; it does not always return the correct count.

If you cannot figure out the bug, try testing a few more samples in count.test.js.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
@RomanSanaye
Copy link
Author

Hi @cjyuan , thanks for your feedback.

I have addressed all the comments:

  • Updated the function to always return a number instead of a string
  • Fixed the bug in countChar by removing the early return inside the loop so it now correctly counts all characters
  • Improved test descriptions to use “return” instead of “print”
  • Made test descriptions more informative by including the “when…” part
  • Simplified ordinal number tests by grouping cases (e.g. numbers ending in 4–9 and 0)

I have also added the “Needs Review” label.

Please let me know if anything else is required.

@cjyuan
Copy link
Contributor

cjyuan commented Mar 19, 2026

Changes look good, and thanks for the clear explanation in the responses. Well done.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants